﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 养老金支付系统
{
    public partial class FormGRBHXZ : FormBase
    {
        public FormGRBHXZ()
        {
            InitializeComponent();
        }

        public string GRBH { get; set; }
        string sgrbh;
        string xm;
        string sfzh;
        string yhhm;
        string yhzh;
        string bz;

        void buttonEnabled(bool b)
        {
            button1.Enabled = b;
            button2.Enabled = b;
        }

        void init()
        {
            this.Text = "请选择个人编号";
            this.sgrbh = "";
            this.xm = "";
            this.sfzh = "";
            this.yhhm = "";
            this.yhzh = "";
            this.bz = "";
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
            textBox4.Text = "";
            textBox5.Text = "";
            textBox6.Text = "";
        }
        void find()
        {
            const string sql = @"select top 100 个人编号,姓名,身份证号,银行名称,银行户名,银行帐号
from (select 个人编号,姓名,身份证号,银行名称,银行户名,银行帐号 from 查支付明细 
where 个人编号 like '%'+@GRBH+'%' and 姓名 like '%'+@XM+'%' and 身份证号 like '%'+@SFZH+'%'
and 银行户名 like '%'+@YHHM+'%' and 银行帐号 like '%'+@YHZH+'%' and 备注 like '%'+@BZ+'%') 查支付明细
group by 个人编号,姓名,身份证号,银行名称,银行户名,银行帐号
order by 个人编号,姓名,身份证号,银行名称,银行户名,银行帐号";
            SqlParameter[] p = new SqlParameter[] { 
                new SqlParameter("@GRBH",this.sgrbh),
                new SqlParameter("@XM",this.xm),
                new SqlParameter("@SFZH",this.sfzh),
                new SqlParameter("@YHHM",this.yhhm),
                new SqlParameter("@YHZH",this.yhzh),
                new SqlParameter("@BZ",this.bz)
            };
            dataGridView1.DataSource = SqlHelper.getDataTable(sql, p);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            buttonEnabled(false);
            find();
            buttonEnabled(true);
        }

        private void textBox1_Leave(object sender, EventArgs e)
        {
            this.sgrbh = textBox1.Text;
        }

        private void textBox2_Leave(object sender, EventArgs e)
        {
            this.xm = textBox2.Text;
        }

        private void textBox3_Leave(object sender, EventArgs e)
        {
            this.sfzh = textBox3.Text;
        }

        private void textBox4_Leave(object sender, EventArgs e)
        {
            this.yhhm = textBox4.Text;
        }

        private void textBox5_Leave(object sender, EventArgs e)
        {
            this.yhzh = textBox5.Text;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            init();
        }

        private void FormZFJLXZ_Load(object sender, EventArgs e)
        {
            init();
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (this.dataGridView1.Rows.Count > 0)
            {
                this.GRBH = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }

        private void textBox6_TextChanged(object sender, EventArgs e)
        {
            this.bz = textBox6.Text;
        }
    }
}
